// pages/collect/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    collect: [],
    tabs: [{
        id: 0,
        value: "商品收藏",
        isActive: true
      },
      {
        id: 1,
        value: "品牌收藏",
        isActive: false
      },
      {
        id: 2,
        value: "店铺收藏",
        isActive: false
      },
      {
        id: 3,
        value: "浏览器足迹",
        isActive: false
      }
    ],

    tip_id_pre: 'id_tap_',
    tips: [{
        id: 1,
        value: '全部',
        isActive: true
      },
      {
        id: 2,
        value: '正在热卖',
        isActive: false
      },
      {
        id: 3,
        value: '即将上线',
        isActive: false
      },
    ]
  },
  onShow() {
    const collect = wx.getStorageSync("collect") || [];
    this.setData({
      collect
    });
    console.log(collect)
  },
  handleTabsItemChange(e) {
    // 1 获取被点击的标题索引
    const {
      index
    } = e.detail;
    // 2 修改源数组
    let {
      tabs
    } = this.data;
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    // 3 赋值到data中
    this.setData({
      tabs
    })
  },
  handleTipsItemChange(e) {
    console.log("处理切换标签");
    console.log(e)

    const {
      id
    } = e.target;

    if(id === ''){
      return;
    }

    let {
      tips
    } = this.data;


    let t_id = id.replace(this.data.tip_id_pre, '')

    console.log('点击的tip：' + t_id)
    tips.forEach(
      (v, i) => {
        if (String(v.id) === t_id) {
          console.log(v.id + "  比  " + t_id)
          console.log("真")
          v.isActive = true
        } else {
          console.log(v.id + "  比  " + t_id)
          console.log("假")
          v.isActive = false;
        }
      }
    )
    // 3 赋值到data中
    this.setData({
      tips
    })

    // let tapItems = 
  }
})